package com.smile.frame.api.es.controller;

import com.smile.frame.api.es.document.Product;
import com.smile.frame.api.es.dto.QueryProductDTO;
import com.smile.frame.api.es.service.IEsProductService;
import com.smile.frame.common.page.PageResult;
import com.smile.frame.common.result.Result;
import com.smile.frame.config.log.systemlog.SystemLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author LGC
 */
@RestController
@RequestMapping("/api/es/product")
@Api("ProductController")
public class ProductController {

    @Resource
    private IEsProductService productService;

    @SystemLog
    @ApiOperation("insertProduct")
    @PostMapping("/insertProduct")
    public Result<Boolean> insertProduct(@RequestBody Product product) {
        return Result.ok(productService.insertProduct(product));
    }

    @SystemLog
    @ApiOperation("batchInsertProduct")
    @PostMapping("/batchInsertProduct")
    public Result<Boolean> batchInsertProduct(@RequestBody List<Product> productList) {
        return Result.ok(productService.batchInsertProduct(productList));
    }

    @SystemLog
    @ApiOperation("batchDeleteProductByProductCode")
    @PostMapping("/batchDeleteProductByProductCode")
    public Result<Boolean> deleteProduct(@RequestBody List<String> codeList) {
        return Result.ok(productService.batchDeleteProductByProductCode(codeList));
    }

    @SystemLog
    @ApiOperation("updateProductByProductCode")
    @PostMapping("/updateProductByProductCode")
    public Result<Boolean> updateProductByProductCode(@RequestBody Product product) {
        return Result.ok(productService.updateProductByProductCode(product));
    }

    @SystemLog
    @ApiOperation("searchProductPage")
    @PostMapping("/searchProductPage")
    public PageResult<Product> searchProductPage(@RequestBody QueryProductDTO dto) {
        return productService.searchProductPage(dto);
    }

}
